<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="../mastertemplate/MasterPage.xhtml" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core">
	<ui:define name="left">
		<h:form id="menuForm">
			<ui:insert name="menubar">
				<ui:include src="tools/privilegemenubar.xhtml" />
			</ui:insert>
		</h:form>
	</ui:define>
	<ui:define name="right">
		<h:form id="userForm">			
			<p:growl id="messages" />
			<p:panel header="#{msg.privilege_title}">
				<p:commandButton rendered="#{UserBean.getAccessLevel() == 'WRITE'}"
					id="adduser" icon="ui-icon-plusthick" value="#{msg.general_add}" styleClass="tableHeaderButton"
					update=":editForm" title="#{msg.general_add_tooltip}" action="#{ConsoleUsersBean.addUser}"
					onclick="PF('editDialog').show();">
					<f:setPropertyActionListener target="#{ConsoleUsersBean.createNew}" value="#{true}" />
				</p:commandButton>
				<p:tooltip for="adduser" value="#{msg.general_add_tooltip}"/>
				<p:dataTable var="consoleUser" value="#{ConsoleUsersBean.consoleUsers}" paginatorPosition="bottom"
					paginator="true" rows="10" rowsPerPageTemplate="10,20,50">
					<f:facet name="header">
						<h:outputText value="#{msg.privilege_users_header}" styleClass="tableHeader" />
					</f:facet>
					<p:column headerText="#{msg.table_userid}" style="width:20%" filterBy="#{consoleUser.userId}" filterMatchMode="contains" sortBy="#{consoleUser.userId}">
						<h:outputText value="#{consoleUser.userId}" />
					</p:column>
					<p:column headerText="#{msg.table_name}" styleClass="userSearchColumn" filterBy="#{consoleUser.name}" filterMatchMode="contains" sortBy="#{consoleUser.name}">
						<h:outputText value="#{consoleUser.name}" />
					</p:column>
					<p:column headerText="#{msg.table_status}" filterBy="#{consoleUser.status}" filterOptions="#{ConsoleUsersBean.statusOptions}" filterMatchMode="exact" sortBy="#{consoleUser.status}">
						<h:outputText value="#{consoleUser.status}" style="color:#{consoleUser.status == 'INACTIVE' ? 'red' : 'green'};"/>
					</p:column>
					<ui:remove>
					<p:column headerText="#{msg.table_loginfailurecount}" styleClass="userSearchColumn" filterBy="#{consoleUser.loginFailure}" filterMatchMode="contains" sortBy="#{consoleUser.loginFailure}">
						<h:outputText value="#{consoleUser.loginFailure}" />
					</p:column>
					</ui:remove>	
					<p:column headerText="#{msg.table_usergroup}" styleClass="userSearchColumn" filterBy="#{consoleUser.group.groupName}" filterMatchMode="contains" sortBy="#{consoleUser.group.groupName}">
						<h:outputLink value="#{request.contextPath}/pages/privilege/groups.xhtml">
							<f:param name="selectedGroupId" value="#{consoleUser.group.groupId}"/>
							<h:outputText value="#{consoleUser.group.groupName}" />
						</h:outputLink>
					</p:column>
					<p:column headerText="#{msg.table_actions}"  style="text-align:center;min-width:10px">
						<h:panelGroup>
							<p:commandButton action="#{ConsoleUsersBean.selectUser(consoleUser)}" styleClass="smallButton"
								update=":userForm:userRight_pnl" icon="ui-icon ui-icon-search" id="selectUser"/>
							<p:tooltip for="selectUser" value="#{msg.privilege_users_effectiveRight_view}" />	
							<p:commandButton action="#{ConsoleUsersBean.selectUser(consoleUser)}" styleClass="smallButton"
								update=":editForm" id="edituser" icon="ui-icon ui-icon-pencil"
								rendered="#{UserBean.getAccessLevel() == 'WRITE'}"
								oncomplete="PF('editDialog').show();" >
								<f:setPropertyActionListener target="#{ConsoleUsersBean.createNew}" value="#{false}" />
							</p:commandButton>
							<p:tooltip for="edituser" value="#{msg.general_edit_tooltip}"
								rendered="#{UserBean.getAccessLevel() == 'WRITE'}"/>
							<p:commandButton action="#{ConsoleUsersBean.selectUser(consoleUser)}" styleClass="smallButton" icon="ui-icon ui-icon-trash"
								onclick="PF('confirmDelete').show()" id="deleteuser"
								rendered="#{UserBean.getAccessLevel() == 'WRITE'}" />
							<p:tooltip for="deleteuser" value="#{msg.general_delete_tooltip}"
								rendered="#{UserBean.getAccessLevel() == 'WRITE'}"/>
						</h:panelGroup>
					</p:column>																			
				</p:dataTable>
				<p:outputPanel id="userRight_pnl">
					<h:panelGroup rendered="#{! empty ConsoleUsersBean.selectedUser}">
						<br />
						<br />
					</h:panelGroup>
					<p:dataTable id="entryTable" rendered="#{! empty ConsoleUsersBean.selectedUser}" var="userRight" value="#{ConsoleUsersBean.userRights}" 
						paginatorPosition="bottom"
						paginator="true" rows="10" rowsPerPageTemplate="10,20,50">
						<f:facet name="header">										
							<h:outputText value="#{msg.privilege_users_effectiveRight}" styleClass="tableHeader" />
						</f:facet>															
						<p:column headerText="#{msg.table_typeid}" styleClass="roleSearchColumn">
							<h:outputText value="#{userRight.typeId}" />
						</p:column>
						<p:column headerText="#{msg.table_accesslevel}" styleClass="roleSearchColumn">		
							<h:outputText value="#{userRight.accessLevel}" />	
						</p:column>													
					</p:dataTable>
				</p:outputPanel>
			</p:panel>
		</h:form>
	</ui:define>
	<ui:define name="content">
		<h:form id="deleteForm">
			<p:confirmDialog header="#{msg.general_delete_header}" id="confirmDelete1" modal="true" widgetVar="confirmDelete" width="450" height="80" message="#{msg.confirmDialog_sure}">
				<div style="float: right">
					<p:commandButton value="#{msg.general_ok}" actionListener="#{ConsoleUsersBean.deleteUser}" 
						oncomplete="PF('confirmDelete').hide()" update=":userForm"/>
					<p:commandButton value="#{msg.general_cancel}" oncomplete="PF('confirmDelete').hide()"/>
				</div>
			</p:confirmDialog>		
		</h:form>		
		<p:dialog id="editDialog1" header="#{msg.general_addedit_header}" modal="true" resizable="false"
			widgetVar="editDialog">
			<h:form id="editForm">
				<p:growl id="messages" />
				<h:panelGrid id="editTable" columns="2" styleClass="twoColTableTag twoColTableValue">
					<h:outputText value="#{msg.table_userid}: "/>
					<h:inputText label="#{msg.table_userid}" value="#{ConsoleUsersBean.selectedUser.userId}" required="true" id="userId"
						disabled="#{! empty ConsoleUsersBean.selectedUser.userId}" style="width:100%; min-width:200px"/>
					<h:outputText value="#{msg.table_name}: " />
					<h:inputText label="#{msg.table_name}" required="true" value="#{ConsoleUsersBean.selectedUser.name}" id="userName" 
						style="width:100%"/>
					<h:outputText value="#{msg.table_password}: " />
					<h:inputSecret label="#{msg.table_password}" required="true" id="password" value="#{ConsoleUsersBean.password}" redisplay="true" 
						style="width:100%"/>
					<h:outputText value="#{msg.table_confirmPassword}: " />
					<h:inputSecret label="#{msg.table_confirmPassword}" required="true" id="confirmpassword" value="#{ConsoleUsersBean.confirmPassword}" redisplay="true" 
						style="width:100%"/>
					<h:outputText value="#{msg.table_status}: " />	
					<h:selectOneMenu value="#{ConsoleUsersBean.selectedUser.status}">
							<f:selectItems value="#{ConsoleUsersBean.statuses}"/>
					</h:selectOneMenu>								
					<h:outputText value="#{msg.table_usergroup}: " />	
					<h:selectOneMenu value="#{ConsoleUsersBean.selectedUserGroupName}" style="width:100%">
							<f:selectItems value="#{ConsoleUsersBean.userGroupNames}"/>
					</h:selectOneMenu>											
				</h:panelGrid>
				<br />
				<div style="float: right">
					<p:commandButton value="#{msg.general_save}"
						action="#{ConsoleUsersBean.saveUser}"
						oncomplete="if(args.opSuccess) PF('editDialog').hide()" update=":userForm" />
					<ui:remove>
						<p:commandButton id="decline" value="#{msg.general_cancel}" onclick="PF('editDialog').hide()" type="button" />
					</ui:remove>
				</div>
			</h:form>
		</p:dialog>
	</ui:define>

</ui:composition>
